package generator.website;

import java.util.Iterator;
import org.eclipse.emf.common.util.EList;
import CarProject.*;
import CarProject.impl.*;;

public class ValidationForm
{
  protected static String nl;
  public static synchronized ValidationForm create(String lineSeparator)
  {
    nl = lineSeparator;
    ValidationForm result = new ValidationForm();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = NL + "import javax.servlet.http.HttpServletRequest;" + NL + "import javax.servlet.http.HttpServletResponse;" + NL + "" + NL + "import org.apache.struts.action.Action;" + NL + "import org.apache.struts.action.ActionErrors;" + NL + "import org.apache.struts.action.ActionForm;" + NL + "import org.apache.struts.action.ActionForward;" + NL + "import org.apache.struts.action.ActionMapping;" + NL + "import org.apache.struts.action.ActionMessage;" + NL + "" + NL + "public class Add";
  protected final String TEXT_2 = "ValidationForm extends ActionForm{" + NL + "" + NL + "\t";
  protected final String TEXT_3 = NL + "\t\tpublic ";
  protected final String TEXT_4 = " ";
  protected final String TEXT_5 = ";" + NL + "\t\t";
  protected final String TEXT_6 = NL + "\t" + NL + "\t//get and set methods" + NL + "\t";
  protected final String TEXT_7 = NL + "\t\tpublic ";
  protected final String TEXT_8 = " get";
  protected final String TEXT_9 = "(){" + NL + "\t\treturn ";
  protected final String TEXT_10 = ";}" + NL + "\t\t" + NL + "\t\tpublic void set";
  protected final String TEXT_11 = "(";
  protected final String TEXT_12 = " new";
  protected final String TEXT_13 = "){" + NL + "\t\tthis.";
  protected final String TEXT_14 = "= new";
  protected final String TEXT_15 = ";}" + NL + "\t\t";
  protected final String TEXT_16 = NL + "\t" + NL + "\tpublic ActionForward execute(ActionMapping mapping, ActionForm form," + NL + "\t\tHttpServletRequest request, HttpServletRespons response){" + NL + "\t\tString success = new String(\"success\");" + NL + "\t\tString error = new String(\"error\");";
  protected final String TEXT_17 = NL + "\t\t";
  protected final String TEXT_18 = " ";
  protected final String TEXT_19 = " = (";
  protected final String TEXT_20 = ") request.getAttribute(\"";
  protected final String TEXT_21 = "\");";
  protected final String TEXT_22 = NL + "\t\treturn mapping.findForward(success);" + NL + "\t}" + NL + "\t\t" + NL + "\tpublic ActionForward validate(ActionMapping mapping," + NL + "\t\t\tHttpServletRequest request) {" + NL + "\t\tActionErrores errors = new ActionReerors();";
  protected final String TEXT_23 = "if(get";
  protected final String TEXT_24 = "() == null || get";
  protected final String TEXT_25 = "().length() < 1){" + NL + "\t\t\terrors.add(\"";
  protected final String TEXT_26 = "\", new ActionMassage(\"creation.fn.error.required\"));" + NL + "\t\t}" + NL + "\t\t";
  protected final String TEXT_27 = NL + "\t\treturn errors;" + NL + "\t}" + NL + "\t" + NL + "\tpublic void reset(ActionMapping mapping, HttpServletRequest request) {";
  protected final String TEXT_28 = NL + "\t\tthis.";
  protected final String TEXT_29 = " = null;";
  protected final String TEXT_30 = NL + "\t}" + NL + "\t" + NL + "}" + NL + "\t" + NL + "\t" + NL + "\t";

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
     SiteWeb site = (SiteWeb) argument; 
    TableImpl laTable=(TableImpl)site.getBasedonnees().getEstCompose().get(0);
    EList<Champs> listChamps = laTable.getPossede();
    String type=null;
    stringBuffer.append(TEXT_1);
    stringBuffer.append(laTable.getNom());
    stringBuffer.append(TEXT_2);
    for (int i = 0;i<listChamps.size();i++){
	if(((ChampsImpl)laTable.getPossede().get(i)).getType().getValue()== EnumType.VARCHAR){ type = "String"; } else { type = "long"; }
	
    stringBuffer.append(TEXT_3);
    stringBuffer.append(type);
    stringBuffer.append(TEXT_4);
    stringBuffer.append(((ChampsImpl)laTable.getPossede().get(i)).getNom());
    stringBuffer.append(TEXT_5);
    
	}
	
    stringBuffer.append(TEXT_6);
    for (int i = 0;i<listChamps.size();i++){
		if(((ChampsImpl)laTable.getPossede().get(i)).getType().getValue()== EnumType.VARCHAR){ type = "String"; } else { type = "long"; }
	
    stringBuffer.append(TEXT_7);
    stringBuffer.append(type);
    stringBuffer.append(TEXT_8);
    stringBuffer.append(((ChampsImpl)laTable.getPossede().get(i)).getNom());
    stringBuffer.append(TEXT_9);
    stringBuffer.append(((ChampsImpl)laTable.getPossede().get(i)).getNom());
    stringBuffer.append(TEXT_10);
    stringBuffer.append(((ChampsImpl)laTable.getPossede().get(i)).getNom());
    stringBuffer.append(TEXT_11);
    stringBuffer.append(type);
    stringBuffer.append(TEXT_12);
    stringBuffer.append(((ChampsImpl)laTable.getPossede().get(i)).getNom());
    stringBuffer.append(TEXT_13);
    stringBuffer.append(((ChampsImpl)laTable.getPossede().get(i)).getNom());
    stringBuffer.append(TEXT_14);
    stringBuffer.append(((ChampsImpl)laTable.getPossede().get(i)).getNom());
    stringBuffer.append(TEXT_15);
    
	}
	
    stringBuffer.append(TEXT_16);
    
		for(int i=0;i<listChamps.size();i++){
			if(((ChampsImpl)laTable.getPossede().get(i)).getType().getValue()== EnumType.VARCHAR){ type = "String"; } else { type = "long"; }
    stringBuffer.append(TEXT_17);
    stringBuffer.append(type);
    stringBuffer.append(TEXT_18);
    stringBuffer.append(((ChampsImpl)laTable.getPossede().get(i)).getNom());
    stringBuffer.append(TEXT_19);
    stringBuffer.append(type);
    stringBuffer.append(TEXT_20);
    stringBuffer.append(((ChampsImpl)laTable.getPossede().get(i)).getNom());
    stringBuffer.append(TEXT_21);
    
		}
    stringBuffer.append(TEXT_22);
    
		for(int i=0;i<listChamps.size();i++){
		
    stringBuffer.append(TEXT_23);
    stringBuffer.append(listChamps.get(i).getNom());
    stringBuffer.append(TEXT_24);
    stringBuffer.append(listChamps.get(i).getNom());
    stringBuffer.append(TEXT_25);
    stringBuffer.append(listChamps.get(i).getNom());
    stringBuffer.append(TEXT_26);
    }
    stringBuffer.append(TEXT_27);
    
		for(int i=0;i<listChamps.size();i++){
    stringBuffer.append(TEXT_28);
    stringBuffer.append(listChamps.get(i).getNom());
    stringBuffer.append(TEXT_29);
    }
    stringBuffer.append(TEXT_30);
    return stringBuffer.toString();
  }
}
